package com.coincalf.wallet.blockchain.bean.xrp;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * XRP地址历史交易纪录记录返回值
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class XrpTxs {

    //查询的地址
    @JsonProperty(value = "account")
    private String account;

    @JsonProperty(value = "ledger_index_max")
    private long ledgerIndexMax;

    @JsonProperty(value = "ledger_index_min")
    private long ledgerIndexMin;

    //交易查询限制数量 0则表示没有限制
    @JsonProperty(value = "limit")
    private String limit;

    //状态 success 则为查询成功
    @JsonProperty(value = "status")
    private String status;

    //交易详情
    @JsonProperty(value = "transactions")
    private List<Transactions> transactions;

    @JsonProperty(value = "validated")
    private boolean validated;

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class Transactions {

        @JsonProperty(value = "meta")
        private Meta meta;

        @JsonProperty(value = "tx")
        private Tx tx;

        //是否验证
        @JsonProperty(value = "validated")
        private boolean validated;

        @Data
        @JsonInclude(JsonInclude.Include.NON_NULL)
        public static class Meta {
            //本次交易收到影响的地址
            @JsonProperty(value = "AffectedNodes")
            private List<Object> affectedNodes;

            @JsonProperty(value = "TransactionIndex")
            private long transactionIndex;

            //本次交易结果 成功为 tesSUCCESS
            @JsonProperty(value = "TransactionResult")
            private String transactionResult;

            //转账数量 交易失败则没有此字段 实际转账数量以这个为准 不能使用Tx的amount
            @JsonProperty(value = "delivered_amount")
            private BigDecimal deliveredAmount;
        }

        @Data
        @JsonInclude(JsonInclude.Include.NON_NULL)
        public static class Tx {

            //本次交易转账地址
            @JsonProperty(value = "Account")
            private String fromAddress;

            //转账数量 单位：最小单位 需要除以1000000才是XRP
            @JsonProperty(value = "Amount")
            private BigDecimal amount;

            //收款地址
            @JsonProperty(value = "Destination")
            private String toAddress;

            //交易标识 tag 类似EOS的memo
            @JsonProperty(value = "DestinationTag")
            private String tag;

            //手续费（矿工费）
            @JsonProperty(value = "Fee")
            private BigDecimal fee;

            @JsonProperty(value = "Flags")
            private long flags;

            @JsonProperty(value = "Sequence")
            private long sequence;

            @JsonProperty(value = "SigningPubKey")
            private String signingPubKey;

            //交易类型 普通转账为 Payment
            @JsonProperty(value = "TransactionType")
            private String transactionType;

            @JsonProperty(value = "TxnSignature")
            private String txnSignature;

            @JsonProperty(value = "date")
            private long date;

            //交易哈希
            @JsonProperty(value = "hash")
            private String hash;

            //区块高度
            @JsonProperty(value = "inLedger")
            private int inLedger;

            @JsonProperty(value = "ledger_index")
            private int blockHeight;
        }
    }

}
